package com.qding.park.manager.web.conf;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.baidu.disconf.client.common.annotations.DisconfFile;
import com.baidu.disconf.client.common.annotations.DisconfFileItem;

@Service
@Scope("singleton")
@DisconfFile(filename = "systemConfig.properties")
public class SystemConfig {
	
	private static String fileDomain;
	
	private static String demoParking;


	@DisconfFileItem(name = "demo.parking", associateField = "demoParking")
	public static String getDemoParking() {
		return demoParking;
	}

	public static void setDemoParking(String demoParking) {
		SystemConfig.demoParking = demoParking;
	}


	public static String projectByParkId(int parkId){
		String projectId="";
		
		JSONArray  json=JSONArray.parseArray(demoParking);
		
		for(int i=0;i<json.size();i++){
			int parkId01=json.getJSONObject(i).getIntValue("parkId");
			if(parkId==parkId01){
				projectId=json.getJSONObject(i).getString("project");
				break;
			}
			
		}
		return projectId;
	}
	
	public static List<String> calculationDemoProject() {

		List<String> projects = new ArrayList<String>();
		
		JSONArray  json=JSONArray.parseArray(demoParking);
		for(int i=0;i<json.size();i++){
		    String project01=json.getJSONObject(i).getString("project");
			projects.add(String.valueOf(project01));
			
		}
		return projects;
	}
	
	
	public static List<String> calculationDemoPark() {

		List<String> projects = new ArrayList<String>();
		
		JSONArray  json=JSONArray.parseArray(demoParking);
		for(int i=0;i<json.size();i++){
			int parkId01=json.getJSONObject(i).getIntValue("parkId");
			projects.add(String.valueOf(parkId01));
			
		}
		return projects;

	}

	@DisconfFileItem(name = "file.domain",associateField ="fileDomain")
	public static String getFileDomain() {
		return fileDomain;
	}

	public static void setFileDomain(String fileDomain) {
		SystemConfig.fileDomain = fileDomain;
	}
	
	
	
}
